package org.csu.mybigpro.controller;


import jakarta.annotation.Resource;
import org.csu.mybigpro.domain.Training;
import org.csu.mybigpro.service.TrainingService;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/training")
public class TrainingController {
    @Resource
    private TrainingService trainingService;

    // 增加实训记录
    @PostMapping("/add")
    public boolean addTraining(@RequestBody Training training) {
        return trainingService.addTraining(training);
    }

    // 修改实训记录
    @PutMapping("/update")
    public boolean updateTraining(@RequestBody Training training) {
        return trainingService.updateTraining(training);
    }

    // 删除实训记录
    @DeleteMapping("/delete/{id}")
    public boolean deleteTraining(@PathVariable Long id) {
        return trainingService.deleteTrainingById(id);
    }

    // 按名称模糊查询
    @GetMapping("/searchByName")
    public List<Training> searchByName(@RequestParam String name) {
        return trainingService.getTrainingsByName(name);
    }

    // 按课程筛选
    @GetMapping("/searchByCourse")
    public List<Training> searchByCourse(@RequestParam String course) {
        return trainingService.getTrainingsByCourse(course);
    }

    // 按类型筛选（线上/线下）
    @GetMapping("/searchByType")
    public List<Training> searchByType(@RequestParam String type) {
        return trainingService.getTrainingsByType(type);
    }

    // 按状态筛选（进行中/已结束/即将开始）
    @GetMapping("/searchByStatus")
    public List<Training> searchByStatus(@RequestParam String status) {
        return trainingService.getTrainingsByStatus(status);
    }

    // 按负责人筛选
    @GetMapping("/searchByManager")
    public List<Training> searchByManager(@RequestParam String manager) {
        return trainingService.getTrainingsByManager(manager);
    }

    @GetMapping("/all")
    public List<Training> getAllTrainings() {
        return trainingService.getAllTrainings();
    }
}
